import {base, high, ajax} from 'nc-lightapp-front';
import 'ssccommon/components/globalPresetVar';
import {setTableExtendCol} from 'ssccommon/components/profile'
import requestApi from '../requestApi';
import {getMultiLang, toast, pageTo, viewModel} from 'nc-lightapp-front';
import {Form} from 'ssccommon/components/bill';
import buttonClick  from './buttonClick';


//变量设置规范，如需要
window.presetVar = {
    ...window.presetVar,
    appcode: '201101FTGZ',
    pagecode: '201101FTGZZ_card'
};

export default function (props) {
    const self = this
    props.createUIDom({
        appcode: props.getAppCode(), //小应用编码,
        pagecode: props.getPageCode(),//页面编码
    }, async data => {

        let buttonTpl = data.button;
        let meta = data.template;
        meta.rule_code.items = meta.rule_code.items.map(item => {
            if (item.attrcode === 'ruleobj_name') { // 分摊对象 需要特殊处理下，预置的类型是input类型  需要改成参照类型  振宇、金泉提供的refcode、beanId
                return Object.assign({}, item, {
                    // "datatype":"204",
                    "itemtype":"refer",
                    // "metadataProperty":"uap.entity.name",
                    // "onlyLeafCanSelect":false,
                    isTreelazyLoad: true,
                    "refcode":"uap/refer/riart/mdTreeByIdRef/index.js",
                    queryCondition: () => {
                        return {
                            beanId: 'cf21a746-807a-4cf8-911f-f397529ee06e',
                            TreeRefActionExt: ''
                        }
                    }
                })
            }
            return item;
        });
        meta.rule_data.items.forEach((item) => {
            if (item.attrcode == 'assume_dept') {
                item.isShowUnit = true;
                item.queryCondition = () => {
                    return {
                        TreeRefActionExt: 'nccloud.web.erm.action.ref.sqlbuilder.DeptTreeRefSqlBuilder',
                        DataPowerOperationCode: 'fi',
                        isDataPowerEnable: 'Y'
                    };
                };
            }
        });

        props.meta.setMeta(meta);
        //设置按钮模板
        if (buttonTpl && buttonTpl.length) {
            props.button.setButtons(buttonTpl);
            //设置按钮显示隐藏
            props.button.setButtonsVisible({
                Save: false,
                Cancel: false,
                Edit: false,
                Refresh: false,
                Delete: false,
                AddLine: false,
                DelLine: false
            });
        }

        // // 获取左侧树
        // let treeData = await new Promise(resolve => {
        //     requestApi.getTreeData({
        //         data: {},
        //         success(data) {
        //             resolve(data);
        //         }
        //     });
        // });
        // let orginfo = [];
        // if (treeData.data && treeData.data[0] && treeData.data[0][0]) {
        //     orginfo = treeData.data[0] && treeData.data[0][0];
        // }
        // // 左树数据打平
        // let treenode = (treeData.data && treeData.data[1] || []).map(item => {
        //     item.pid = null;
        //     item.refname = item.refname || item.name;
        //     return item;
        // });

        // if (treenode && treenode.length === 0) return;

        // let {syncTree} = props;
        // let {setSyncTreeData} = syncTree;
        // let newTree = syncTree.createTreeData(treenode); //创建树 组件需要的数据结构
        // setSyncTreeData('tree1', newTree);

        // //请求分摊规则详情数据
        // let reqData = {
        //     pagecode: props.getPageCode(),
        //     pk: treenode[0].refpk || treenode[0].refcode,
        //     pk_org: orginfo[0]
        // };
        // let tableData = await new Promise(resolve => {
        //     requestApi.getTableData({
        //         data: reqData,
        //         success: (data) => {
        //             resolve(data);
        //         }
        //     });
        // });
        // // 选中左树选中项
        // syncTree.setNodeSelected('tree1', treenode[0].refpk);

        // buttonClick.setMetaDataFromTreeNode(tableData, props);
    })


}


